package com.tedu.violation.service.impl;

import com.tedu.user.pojo.vo.UserViolationRecordVO;
import com.tedu.violation.mapper.ViolationRecordMapper;
import com.tedu.violation.pojo.entity.ViolationRecord;
import com.tedu.violation.service.ViolationRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class ViolationRecordServiceImpl implements ViolationRecordService {

    @Autowired
    private ViolationRecordMapper violationRecordMapper;
    @Override
    public List<UserViolationRecordVO> selectViolationRecordByUserId(Integer userId) {
        log.debug("查看违规详情-入参：{}",userId);
        List<ViolationRecord> violations = violationRecordMapper.selectViolationRecordByUserId(userId);
        // 将 ViolationRecord 转换为 UserViolationRecordDTO
        return violations.stream()
                .map(record -> {
                    UserViolationRecordVO dto = new UserViolationRecordVO();
                    dto.setViolationTime(record.getViolationTime());
                    dto.setReason(record.getReason());
                    return dto;
                })
                .collect(Collectors.toList());
    }
}
